<html>
<head>
	<meta charset='utf-8' />
	<title>记事本</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}

		.e1{border:0px solid;flex-basis:150px;flex-grow:1;padding:10px}
		.e2{height:150px;width:100px;border:1px solid #555;margin:auto;padding:10px 15px 30px 15px;background:#aaa}
		.e3{height:100%;word-break:break-all;border:0px solid;overflow:hidden}
	</style>
</head>
<body style='padding:0;margin:0;background:#ccc'>
<!-- 1 Content容器 -->
<div id='Content' style='border:0px solid'>
	<div style='text-align:right;font-size:13px;margin:10px'>
		<a href='index_create.html' style='text-decoration:none'>新建</a>　
		当前用户：<span id='UserName' style='color:#658'>10001</span>　
		<span style='color:#660' id='exit'>退出</span>
	</div>

	<div style='text-align:center;margin:20px auto'>
		<input type="text" id='search_inp' />
		<button id='search_btn'>搜索</button>
	</div>
	
	<!--列表-->
	<div id='list' style='display:flex;flex-wrap:wrap;'></div>

	<div style='height:50px'></div>
</div><!-- 1 Content容器结束 -->


</body>
</html>
<script src='public/jquery.js'></script>
<script src='public/fun.js'></script>
<script>
if(!sessionStorage.search){
	sessionStorage.search = '';
}else{
	$('#search_inp').val(sessionStorage.search);
}

CheckLoginBefore();		//### 检测前台登陆状态和token1

$('#search_btn').click(function(){
	var search = $('#search_inp').val().trim();
	if(sessionStorage.search == search){
		return;
	}
	sessionStorage.search = search;
	location.reload();
});



function GetNotpadList(){
	AjaxBefore({type:'GetNotpadList','search':sessionStorage.search},function(res){
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		ParseData(tmp.data);	//解析数据
	})
}
function ParseData(data){
	var tmp_str = '';
	if(data.length > 0){
		for(var i=0;i<data.length;i++){
	 		tmp_str += "<div class='e1'><div class='e2'><div class='e3' onclick='JumpDedail("+ data[i].id +")'><textarea style='width:100%;height:100%;background:#aaa;border:0px;resize:none' readonly >"+ data[i].title +"</textarea></div></div></div>"
		}
	}
	$('#list').html(tmp_str);
}

$(function(){
	//获取记事本列表
	GetNotpadList();




	//显示当前用户名
	$('#UserName').text(sessionStorage.user).click(function(){
		location.href='index_pwd.html';
	});

	//退出
	$('#exit').click(function(){
		AjaxBefore({type:'exit'},function(res){
			if(res == 'ok'){
				sessionStorage.user = '';
				sessionStorage.token1 = '';
				A('成功退出！');
				location.replace('login.html');
			}
		});
	});

});
function JumpDedail(id){
	if(!id){
		return;
	}
	sessionStorage.current_id = id;
	location.href='index_detail.html';
}
</script>